<?php

class Application {
	
	private $_db;
	private $_debug = false;
	private $_defaultController;
	private $_staticUrls;
	private $_urlManager;

	public function __construct($settings){

		$set = require_once($settings);
		$this->_db = new MySQL($set['db']);
		$this->_defaultController = $set['defaultController'];
		$this->_urlManager = $set['urlManager'];
		$this->_staticUrls = $set['staticUrls'];
		$this->_debug = $set['debug'];
	}

	public function run(){

		$url = new $this->_urlManager($this->_staticUrls);

		list($controllerName,$action) = $url->parse();

		require_once APP_PATH.DS."controllers".DS.$controllerName.".php";

		// create controller
		$controller = new $controllerName();

		if (method_exists($controller,$action)){
			$controller->$action();
		} else {
			throw new Exception("The $controllerName has not method $action");
		}
	}


}

?>